package com.lonely.fx.bind;

import javafx.application.Application;
import javafx.beans.binding.NumberBinding;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.stage.Stage;

/**
 * @date: 2022-07-24 13:14
 * @author: ztkj-hzb
 * @description: 绑定计算
 **/
public class BindComputationSettingMain extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /**
     *
     */
    @Override
    public void start(Stage primaryStage) throws Exception {


        int x = 10,y=8;
        int z = x+y;
        System.out.println("z:" + z);

        x = 8;
        System.out.println("z:" + z);

        System.out.println("----------------------------------------------------");



        SimpleIntegerProperty a = new SimpleIntegerProperty(10);

        SimpleIntegerProperty b = new SimpleIntegerProperty(2);

        //add
        NumberBinding addBind = a.add(b);
        System.out.println(addBind.getValue().intValue());

        a.set(20);
        System.out.println(addBind.getValue().intValue());


        //subtract
        NumberBinding subtractBind = a.subtract(b);
        System.out.println(subtractBind.getValue().intValue());
        a.set(10);
        System.out.println(subtractBind.getValue().intValue());



    }
}
